package com.schoolhelper.controller.adapter;

import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import androidx.annotation.NonNull;
import androidx.viewpager.widget.PagerAdapter;

import java.util.ArrayList;

public class MainViewPagerAdapter extends PagerAdapter {

    private ArrayList<ImageView> images;

    public MainViewPagerAdapter(ArrayList<ImageView> images){
        this.images = images;
    }


    @Override
    public int getCount() {
        return images.size();
    }

    @Override
    public boolean isViewFromObject(@NonNull View view, @NonNull Object object) {
        return view == object;
    }

    @NonNull
    @Override
    public Object instantiateItem(@NonNull ViewGroup container, int position) {
        //将图片加进容器
        View v = images.get(position);
        container.addView(v);
        return v;

    }

    @Override
    public void destroyItem(@NonNull ViewGroup container, int position, @NonNull Object object) {
        //将图片移出容器
        View v = images.get(position);
        container.removeView(v);
    }
}
